//
//  DTNetWork.m
//  DanTang
//
//  Created by honeyrr on 2017/9/11.
//  Copyright © 2017年 honeyrr. All rights reserved.
//

#import "DTNetWork.h"
#import "AFNetworking.h"
#import "SVProgressHUD.h"

@implementation DTNetWork

static id _instance;
//单例
+(instancetype)sharedNetWork
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [[self alloc]init];
    });
    return _instance;
}

//get请求
-(void)loadDataInfo:(NSString *)urlString
       parameters:(id)parameters
       success:(void (^)(id _Nullable))success
       failure:(void (^)(NSError * _Nullable))failure
{
    urlString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    [SVProgressHUD showWithStatus:@"正在加载..."];
    [[AFHTTPSessionManager manager] GET:urlString parameters:parameters success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        success(responseObject);
        [SVProgressHUD showSuccessWithStatus:@"加载完成"];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [SVProgressHUD showErrorWithStatus:@"加载失败"];
    }];
    [SVProgressHUD dismiss];
}

@end
